import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

const home = r => require.ensure([], () => r(require('@/views/home/home')), 'home')
const channel = r => require.ensure([], () => r(require('@/views/home/children/channel')), 'channel')
const player = r => require.ensure([], () => r(require('@/views/player/player')), 'player')
const found = r => require.ensure([], () => r(require('@/views/found/found')), 'found')
const mine = r => require.ensure([], () => r(require('@/views/mine/mine')), 'mine')
const login = r => require.ensure([], () => r(require('@/views/login/login')), 'login')
const register = r => require.ensure([], () => r(require('@/views/register/register')), 'register')
const ip = r => require.ensure([], () => r(require('@/views/found/children/ip')), 'ip')
const rank = r => require.ensure([], () => r(require('@/views/found/children/rank')), 'rank')
const rankList = r => require.ensure([], () => r(require('@/views/found/children/children/rankList')), 'rankList')
const spec = r => require.ensure([], () => r(require('@/views/found/children/spec')), 'spec')
const aip = r => require.ensure([], () => r(require('@/views/ipspec/aip')), 'aip')
const aspec = r => require.ensure([], () => r(require('@/views/ipspec/aspec')), 'aspec')
const mycolle = r => require.ensure([], () => r(require('@/views/mycolle/mycolle')), 'mycolle')
const mysubs = r => require.ensure([], () => r(require('@/views/mysubs/mysubs')), 'mysubs')

const myip = r => require.ensure([], () => r(require('@/views/mysubs/children/myip')), 'myip')
const myspec = r => require.ensure([], () => r(require('@/views/mysubs/children/myspec')), 'myspec')
const userinfo = r => require.ensure([], () => r(require('@/views/userinfo/userinfo')), 'userinfo')
const password = r => require.ensure([], () => r(require('@/views/password/password')), 'password')

Vue.use(Router)
const scrollBehavior = (to, from, savedPosition) => {
	if (savedPosition) {
		return savedPosition
	} else {
		if (from.meta.keepAlive) {
			from.meta.savedPosition = document.body.scrollTop;
		}
		return { x: 0, y: to.meta.savedPosition || 0 }
	}
}

export default new Router({
	scrollBehavior,
	linkActiveClass: 'active',
	routes: [
		{
			path: '/home',
			name: 'home',
			component: home,
			children: [
				{
					path: ':menu_id',
					name: 'channel',
					component: channel,
				},
			]
		},
		{
			path: '/player/:aid',
			name: 'player',
			component: player,
            meta: { footer: true },
		},
		{
			path: '/found',
			name: 'found',
			component: found,
			children: [
				{
					path: 'ip',
					component: ip,
				},
				{
					path: 'rank',
					component: rank,
					children: [
						{
							path: ':menu_id',
							name: 'rankList',
							component: rankList,
						}
					]
				},
				{
					path: 'spec',
					component: spec,
				},
			]

		},
		{
			path: '/aip/:ip_id',
			name: 'aip',
			component: aip,
            meta: { footer: true },
		},
		{
			path: '/aspec/:subject_id',
			name: 'aspec',
			component: aspec,
            meta: { footer: true },
		},
		{
			path: '/mine',
			name: 'mine',
			component: mine,

		},
		{
			path: '/mycolle',
			name: 'mycolle',
			component: mycolle,
            meta: { footer: true },
		},
		{
			path: '/mysubs',
			name: 'mysubs',
			component: mysubs,
			meta: { footer: true },
			// children: [
			// 	{
			// 		path: 'myip',
			// 		component: myip,
			// 	},
			// 	{
			// 		path: 'myspec',
			// 		component: myspec,
			// 		meta: { footer: true },
			// 	},
			// ]
		},
		{
			path: '/userinfo',
			name: 'userinfo',
			component: userinfo,
			meta: { footer: true },
		},
		{
			path: '/password',
			name: 'password',
			component: password,
			meta: { footer: true },
		},
		{
			path: '/login',
			name: 'login',
			component: login,
            meta: { footer: true },
		},
		{
			path: '/register',
			name: 'register',
			component: register,
            meta: { footer: true },
		},
	]
})
